//
//  HTTPTestViewController.swift
//  sss
//
//  Created by hrrMac on 2020/6/30.
//  Copyright © 2020 hrrMac. All rights reserved.
//

import UIKit
class HTTPTestViewController: BaseViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
//        httpData()
        http()
        // Do any additional setup after loading the view.
    }
    
    
    func http(){
        view.mbShowLoadingText("加载中")
        let dict = ["token": "fcb461f60a79a420864cb5ef8773ebc1",
        "start": "0",
        "limit": "10"]
        AF.request("http://wish.caisxs.com:8001/api/videoList", method: .post, parameters: dict, encoding: JSONEncoding.default).responseJSON { [weak self] (response) in
            switch response.result{
            case .success:
                self?.view.mbShowToast("加载成功")
            case .failure(let error):
                self?.view.mbShowToast("加载失败")
            }
        }
        
    }

    func httpData() {
        let dict = ["token": "fcb461f60a79a420864cb5ef8773ebc1",
            "start": "0",
            "limit": "10"] 
    
//        view.mbShowToast("加载中")
        view.mbShowLoadingText("加载中")
        
        
//        return;
        HTTPPOST("http://wish.caisxs.com:8001/api/videoList", parameters: dict, result: { [weak self] (result)  in
            if result.status == .success {
                print("请求成功")
                self?.view.mbShowToast("加载成功")
                if result.dataArr.count > 0 {
                    let one: VideoTestModel = result.dataArr.first as! VideoTestModel
                    print("user_id : " + one.user_id)
                }
                
            }else{
                print("请求失败")
                self?.view.mbShowToast("加载失败")
            }
        }, model: VideoTestModel.self)
    }
    
    
    // MARK: - 析构函数
//    deinit{
//        print("deinit: \(self.description)")
//    }
}


struct  VideoTestModel :Convertible {
    
    var id :String!
    var video :String!
    var user_id :String!
    var avatar: String!
}
